package com.postsuperman.proxypool.pojo;

import com.postsuperman.proxypool.dao.Constant;
import org.apache.http.HttpHost;
import org.springframework.data.annotation.Id;
import org.springframework.data.mongodb.core.mapping.Document;

import java.io.Serializable;

/**
 * @author ： postsuperman
 * Created by 11:22 on 2019/2/26.
 */
@Document(collection = Constant.COL_NAME_PROXY)
public class HttpProxy implements Serializable {

    @Id
    private String id;

    //ip地址   121.236.238.89
    private String ip;

    //端口  33502
    private Integer port;

    //城市  苏州市
    private String city;

    //运营商  电信
    private String isp;

    //分值
    private Double score;

    private String type = "http";      //http、https

    private Long lastUpdateTime;

    private Long createTime;

    //响应时长
    private Long ms;

    //质量等级：0 普通，1 优质
    private Integer level = 0;

    public HttpProxy(){}

    public HttpProxy(String ip, Integer port) {
        this.ip = ip;
        this.port = port;
    }

    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }

    public String getIp() {
        return ip;
    }

    public void setIp(String ip) {
        this.ip = ip;
    }

    public Integer getPort() {
        return port;
    }

    public void setPort(Integer port) {
        this.port = port;
    }

    public String getCity() {
        return city;
    }

    public void setCity(String city) {
        this.city = city;
    }

    public String getIsp() {
        return isp;
    }

    public void setIsp(String isp) {
        this.isp = isp;
    }

    public Double getScore() {
        return score;
    }

    public void setScore(Double score) {
        this.score = score;
    }

    public Long getLastUpdateTime() {
        return lastUpdateTime;
    }

    public void setLastUpdateTime(Long lastUpdateTime) {
        this.lastUpdateTime = lastUpdateTime;
    }

    public String getType() {
        return type;
    }

    public void setType(String type) {
        this.type = type;
    }

    public Long getCreateTime() {
        return createTime;
    }

    public void setCreateTime(Long createTime) {
        this.createTime = createTime;
    }

    public Long getMs() {
        return ms;
    }

    public void setMs(Long ms) {
        this.ms = ms;
    }

    public Integer getLevel() {
        return level;
    }

    public void setLevel(Integer level) {
        this.level = level;
    }

    /**
     * 将Proxy转换成一个HttpHost对象
     *
     * @return
     */
    public HttpHost toHttpHost() {

        return new HttpHost(ip, port, type);
    }

    @Override
    public String toString() {
        return ip + ":" + port;
    }

    public static final String ID = "id";
    public static final String IP = "ip";
    public static final String PORT = "port";
    public static final String CITY = "city";
    public static final String ISP = "isp";
    public static final String SCORT = "score";
    public static final String TYPE = "type";
    public static final String LASTUPDATE_TIME = "lastUpdateTime";
    public static final String CREATE_TIME = "createTime";
    public static final String MS = "ms";
}

